package br.estacio.contatos.client.activity.mapper;

import br.estacio.contatos.client.ClientFactory;
import br.estacio.contatos.client.activity.EditarContatoActivity;
import br.estacio.contatos.client.activity.InicioActivity;
import br.estacio.contatos.client.activity.ListarContatoActivity;
import br.estacio.contatos.client.place.EditarContatoPlace;
import br.estacio.contatos.client.place.InicioPlace;
import br.estacio.contatos.client.place.ListarContatoPlace;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;

public class AppActivityMapper implements ActivityMapper {

	private ClientFactory clientFactory;

	public AppActivityMapper(ClientFactory clientFactory) {
		super();
		this.clientFactory = clientFactory;
	}

	@Override
	public Activity getActivity(Place place) {
		
		if (place instanceof InicioPlace)
			return new InicioActivity((InicioPlace) place);
		else if (place instanceof EditarContatoPlace)
			return new EditarContatoActivity((EditarContatoPlace) place, clientFactory.getEditarContatoView(), clientFactory.getContatoRemoteServiceAsync());
		else if(place instanceof ListarContatoPlace) {
			return new ListarContatoActivity((ListarContatoPlace) place, clientFactory.getListarContatoView(), clientFactory.getContatoRemoteServiceAsync());
		}

		return null;
	}

}
